using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using GuavaData;
using System.ComponentModel;

namespace GuavaLib
{
    public class GSplitContainer : SplitContainer, Guava
    {
        Label lab;
        string gname;

        public Label Label
        {
            get
            {
                return lab;
            }
            set
            {
                this.lab = value;
            }
        }

        #region Guava Members

        [Browsable(false)]
        public LaunchType LType
        {
            get { return LaunchType.NA; }
        }

        [Browsable(false)]
        public ControlType CType
        {
            get { return ControlType.Container; }
        }

        [Browsable(false)]
        public string GText
        {
            get
            {
                if (this.lab == null) return null;
                return this.lab.Text;
            }
        }

        public string GName
        {
            get
            {
                if (gname == null) return this.Name;
                return gname;
            }
            set
            {
                this.gname = value;
            }
        }

        [Browsable(false)]
        public System.Drawing.Point GLocation
        {
            get { return this.Location; }
        }

        [Browsable(false)]
        public System.Drawing.Size GSize
        {
            get { return this.Size; }
        }

        [Browsable(false)]
        public List<Guava> GComponents
        {
            get
            {
                List<Guava> lg = new List<Guava>();
                lg.Add(this.GPanel1);
                lg.Add(this.GPanel2);
                return lg;
            }
        }

        public void GBind(string table, int i)
        {
            foreach (Guava c in GComponents)
            {
                c.GBind(table, i);
            }
        }

        [Browsable(false)]
        public string GDefault
        {
            get { return null; }
        }

        [Browsable(false)]
        public string GToolTip
        {
            get
            {
                Control p = this.TopLevelControl;
                if (!(p is Guava)) return null;
                ToolTip t = (p as GuavaForm).GToolTipProvider;
                if (t == null) return null;

                // Fetch the tooltip and return it
                return t.GetToolTip(this);
            }
        }

        [Browsable(false)]
        public GuavaData.Domain.Domain GDomain
        {
            get { return null; }
        }

        public Guava this[string s]
        {
            get
            {
                foreach (Guava g in this.GComponents) if (g.GName == s) return g;
                return null;
            }
        }

        #endregion

        #region Panel Information

        private GSplitterPanel GPanel1
        {
            get
            {
                return new GSplitterPanel(this.Panel1, (Panel1Label == null) ? null : Panel1Label.Text, Panel1Name);
            }
        }
        Label panel1Label;
        public Label Panel1Label
        {
            get { return panel1Label; }
            set { panel1Label = value; }
        }
        string panel1Name;
        public string Panel1Name
        {
            get { return panel1Name; }
            set { panel1Name = value; }
        }

        private GSplitterPanel GPanel2
        {
            get
            {
                return new GSplitterPanel(this.Panel2, (Panel2Label == null) ? null : Panel2Label.Text, Panel2Name);
            }
        }
        Label panel2Label;
        public Label Panel2Label
        {
            get { return panel2Label; }
            set { panel2Label = value; }
        }
        string panel2Name;
        public string Panel2Name
        {
            get { return panel2Name; }
            set { panel2Name = value; }
        }

        #endregion
    }

    internal class GSplitterPanel : Object, Guava
    {
        SplitterPanel bsp;
        string gname, gtext;

        public GSplitterPanel(SplitterPanel sp, string gname, string gtext)
            : base()
        {
            this.bsp = sp;
            this.gname = gname;
            this.gtext = gtext;
        }

        #region Guava Members

        public LaunchType LType
        {
            get { return LaunchType.NA; }
        }

        public ControlType CType
        {
            get { return ControlType.Container; }
        }

        public string GText
        {
            get { return gtext; }
        }

        public string GName
        {
            get
            {
                return gname;
            }
            set
            {
                gname = value;
            }
        }

        public System.Drawing.Point GLocation
        {
            get { return new System.Drawing.Point(bsp.Left, bsp.Top); }
        }

        public System.Drawing.Size GSize
        {
            get { return new System.Drawing.Size(bsp.Width, bsp.Height); }
        }

        public List<Guava> GComponents
        {
            get
            {
                List<Guava> lg = new List<Guava>();
                foreach (Control c in bsp.Controls)
                {
                    if (c is Guava) lg.Add(c as Guava);
                }
                return lg;
            }
        }

        public void GBind(string table, int i)
        {
            foreach (Guava g in GComponents) g.GBind(table, i);
        }

        public string GDefault
        {
            get { return null; }
        }

        public string GToolTip
        {
            get
            {
                Control p = bsp.TopLevelControl;
                if (!(p is Guava)) return null;
                ToolTip t = (p as GuavaForm).GToolTipProvider;
                if (t == null) return null;

                // Fetch the tooltip and return it
                return t.GetToolTip(bsp);
            }
        }

        public GuavaData.Domain.Domain GDomain
        {
            get { return null; }
        }

        public Guava this[string s]
        {
            get
            {
                foreach (Guava g in this.GComponents) if (g.GName == s) return g;
                return null;
            }
        }

        #endregion
    }
}
